package com.shunda.trade.service.impl;


import com.shunda.common.core.domain.entity.SysDept;
import com.shunda.trade.entity.CustomerStationsRecord;
import com.shunda.trade.mapper.CustomerStationsRecordMapper;
import com.shunda.trade.service.CustomerStationsRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息表(CustomerStationsRecord)表服务实现类
 *
 * @author makejava
 * @since 2025-03-14 21:53:18
 */
@Service("customerStationsRecordService")
public class CustomerStationsRecordServiceImpl implements CustomerStationsRecordService {
    @Resource
    private CustomerStationsRecordMapper customerStationsRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param recordId 主键
     * @return 实例对象
     */
    @Override
    public CustomerStationsRecord queryById(Long recordId) {
        return this.customerStationsRecordDao.queryById(recordId);
    }

    /**
     * 分页查询
     *
     * @param customerStationsRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<CustomerStationsRecord> queryByPage(CustomerStationsRecord customerStationsRecord, PageRequest pageRequest) {
        long total = this.customerStationsRecordDao.count(customerStationsRecord);
        return new PageImpl<>(this.customerStationsRecordDao.queryAllByLimit(customerStationsRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param customerStationsRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerStationsRecord insert(CustomerStationsRecord customerStationsRecord) {
        this.customerStationsRecordDao.insert(customerStationsRecord);
        return customerStationsRecord;
    }

    /**
     * 修改数据
     *
     * @param customerStationsRecord 实例对象
     * @return 实例对象
     */
    @Override
    public CustomerStationsRecord update(CustomerStationsRecord customerStationsRecord) {
        this.customerStationsRecordDao.update(customerStationsRecord);
        return this.queryById(customerStationsRecord.getRecordId());
    }

    /**
     * 通过主键删除数据
     *
     * @param recordId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long recordId) {
        return this.customerStationsRecordDao.deleteById(recordId) > 0;
    }

    @Override
    public List<SysDept> selectRecordByUserIdAndTop(Long userId, int top) {
        return customerStationsRecordDao.selectRecordByUserIdAndTop(userId, top);
    }
}
